package com.xiaoxin.model.vo;

import com.xiaoxin.model.domain.UserInfo;
import com.xiaoxin.model.mongo.Movement;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;

/**
 * @author xiaoxiaode
 * @date 2021/9/14 22:37
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MovementsVo2 implements Serializable {

    private String id; //动态id .
    private String nickname; //昵称 .
    private Integer userId; //用户id .
    private String avatar; //头像 .
    private Integer createDate; //发布时间 .
    private String textContent; //文字动态 .
    private String[] imageContent; //图片动态 .
    private Integer state = 0;//状态 0：未审（默认），1：通过，2：驳回 .
    private Integer commentCount = 0; //评论数 .
    private Integer loveCount = 0; //喜欢数 .


    public static MovementsVo2 init(UserInfo userInfo, Movement movement) {
        MovementsVo2 vo = new MovementsVo2();
        //设置动态数据
        BeanUtils.copyProperties(movement, vo);
        vo.setId(movement.getId().toHexString());
        //图片列表
        vo.setImageContent(movement.getMedias().toArray(new String[]{}));
        vo.setState(movement.getState());
        long time = System.currentTimeMillis();
        Integer date=Math.toIntExact(time);
        vo.setCreateDate(date);
        return vo;
    }
}
